package com.it.xuehang.util;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.nio.file.Paths;
import java.util.Collections;

public class CodeGenerator {
    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:dm://localhost:5236", "XUEHANG", "123456")
                .globalConfig(builder -> builder
                        .author("xuehang")
                        .outputDir(Paths.get(System.getProperty("user.dir")) + "/src/main/java")
                        .dateType(DateType.ONLY_DATE) // 设置时间类型策略
                        .commentDate("yyyy-MM-dd") // 设置注释日期格式
                        .disableOpenDir()
                )
                .packageConfig(builder -> builder
                        .parent("com.it.xuehang")
                        .entity("entity")
                        .mapper("mapper")
                        .service("service")
                        .serviceImpl("service.impl")
//                        .xml("mapper.mappers")
                        .controller("controller")
                        .pathInfo(Collections.singletonMap(OutputFile.xml, "src/main/resources/mappers"))
                )
                .strategyConfig(builder -> builder
                        .addInclude("SYNC_LOG")
                        .entityBuilder()
                        .columnNaming(NamingStrategy.underline_to_camel)
                        .enableLombok()
                        .mapperBuilder()
                        .enableBaseResultMap()
                        .enableBaseColumnList()
                        .serviceBuilder()
                        .formatServiceFileName("%sService")
                        .controllerBuilder()
                        .enableRestStyle()
                )
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
